#include "base/core/hash.h"

uint32_t BKDRHashForString32Bit(const char* str) 
{
    uint32_t hashCode = 0;
    while (*str)
        hashCode = (hashCode << 7) + (hashCode << 1) + hashCode + *str++;
    return hashCode;
}

uint64_t BKDRHashForString64Bit(const char* str) 
{
    uint64_t hashCode = 0;
    while (*str)
        hashCode = (hashCode << 7) + (hashCode << 1) + hashCode + *str++;
    return hashCode;
}

uint32_t BKDRHashForString32Bit(const char* str1, const char* str2) 
{
    uint32_t hashCode = 0;
    while (*str1)
        hashCode = (hashCode << 7) + (hashCode << 1) + hashCode + *str1++;
    // (a, aa) (aa, a) ==>(a aa)(aa a) zero never appear in string
    hashCode = (hashCode << 7) + (hashCode << 1) + hashCode /*+ 0*/;
    while (*str2)
        hashCode = (hashCode << 7) + (hashCode << 1) + hashCode + *str2++;

    return hashCode;
}

uint64_t BKDRHashForString64Bit(const char* str1, const char* str2) 
{
    uint64_t hashCode = 0;
    while (*str1)
        hashCode = (hashCode << 7) + (hashCode << 1) + hashCode + *str1++;
    // (a, aa) (aa, a) ==>(a aa)(aa a) zero never appear in string
    hashCode = (hashCode << 7) + (hashCode << 1) + hashCode /*+ 0*/;
    while (*str2)
        hashCode = (hashCode << 7) + (hashCode << 1) + hashCode + *str2++;

    return hashCode;
}
